package cn.tedu._05mvcboot01.controller;

import cn.tedu._05mvcboot01.pojo.dto.UserLoginDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
public class UserController {
    @RequestMapping("/v1/user/login")
    @ResponseBody
    public String login(){

        return "登录成功";

    }

    /**
     * 注册功能
     * GET请求   http://localhost:8080/v1/user/reg/?username=kaluoer&password=123456
     *post请求
     *  <form action="地址" method="post">
     *      <input type="text" name="username">
     *      <input type="text" name="password">
     *      <input type="submit" value="注册">
     *  </form>
     */
    @RequestMapping("/v1/user/reg")
    @ResponseBody
    public String reg(){
        return "注册成功";
    }


    /**
     * 接收数据方式1:通过HttpServletRequest接收;
     *      *  - http://localhost:8080/v1/user/login1?username=xxx&password=yyy
     */

    @RequestMapping("/v1/user/login1")
    @ResponseBody
    public String longin1(HttpServletRequest request){

        String username = request.getParameter("username");
        String password = request.getParameter("password");

        return username + ":" + password;
    }
    /**
     * 接受数据2
     *  http://localhost:8080/v1/user/login2?username=xxx&password=yyy
    */

    @RequestMapping("/v1/user/login2")
    @ResponseBody
    public  String login2(UserLoginDTO userLoginDTO){
        String username = userLoginDTO.getUsername();
        String password = userLoginDTO.getPassword();
        return username + "--------" + password;
    }

    /**
     * 接受数据3 通过声明参数的类型来接收数据
     *  http://localhost:8080/v1/user/login3?username=xxx&password=yyy
     */

    @RequestMapping("/v1/user/login3")
    @ResponseBody
    public String login3(String username,String password){
        return username + "++++++" + password;
    }





}
